<!--
  ~ Copyright (c) 2020 the original author or authors
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      https://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  ~ or implied. See the License for the specific language governing
  ~ permissions and limitations under the License.
  -->
<div class="sign-up-card">
  <p class="sign-up-card--title">
    {{ 'registration.title' | translate }}
  </p>
  <div class="form-card">
    <form class="form-card--form" [formGroup]="form" (ngSubmit)="onSubmit()" id="signUpForm">
      <div class="form-field" appearance="outline" hideRequiredMarker>
        <label>{{ 'registration.first_name' | translate }}</label>
        <input
          formControlName="firstName"
          class="first-name"
          name="firstName"
          required
          placeholder="{{ 'registration.first_name_placeholder' | translate }}"
        />
        <div class="err" *ngIf="form.controls.firstName.status === 'INVALID' && form.controls.firstName.touched && !form.value.firstName">
          {{ 'registration.name_restriction' | translate }}
        </div>
        <div class="err" *ngIf="form.value.firstName?.length > maxInputLength">
          {{ 'common.input_lengh_err' | translate }}
        </div>
      </div>
      <div class="form-field" appearance="outline" hideRequiredMarker>
        <label>{{ 'registration.last_name' | translate }}</label>
        <input
          formControlName="lastName"
          class="last-name"
          name="lastName"
          required
          placeholder="{{ 'registration.last_name_placeholder' | translate }}"
        />
        <div class="err" *ngIf="form.controls.lastName.status === 'INVALID' && form.controls.lastName.touched && !form.value.lastName">
          {{ 'registration.last_name_restriction' | translate }}
        </div>
        <div class="err" *ngIf="form.value.lastName?.length > maxInputLength">
          {{ 'common.input_lengh_err' | translate }}
        </div>
      </div>
      <div class="form-field" appearance="outline" hideRequiredMarker>
        <label>{{ 'registration.email' | translate }}</label>
        <input
          formControlName="email"
          name="email"
          type="email"
          required
          placeholder="{{ 'registration.email_placeholder' | translate }}"
        />
        <span class="err" *ngIf="form.controls.email.status === 'INVALID' && form.controls.email.touched">
          <span>{{ 'registration.email_hint' | translate }}</span>
        </span>
      </div>
      <div class="form-field" appearance="outline" hideRequiredMarker>
        <label
          >{{ 'registration.password' | translate }}
          <small class="hint">{{ 'registration.password_restriction' | translate }}</small>
        </label>
        <input
          formControlName="password"
          type="password"
          name="password"
          required
          placeholder="{{ 'registration.password_placeholder' | translate }}"
        />
        <div
          class="err"
          *ngIf="form.controls.password.status === 'INVALID' && form.controls.password.touched && form.controls.password.dirty"
        >
          <span>{{ 'registration.password_restriction' | translate }}</span>
        </div>
      </div>
      <div class="form-field" appearance="outline" hideRequiredMarker>
        <label>{{ 'registration.confirm_password' | translate }}</label>
        <input
          formControlName="confirmPassword"
          type="password"
          name="confirmPassword"
          required
          placeholder="{{ 'registration.confirm_password_placeholder' | translate }}"
        />
        <div
          class="err"
          *ngIf="
            !form.controls.confirmPassword.pristine && form.controls.confirmPassword.status === 'INVALID' && form.controls.password.touched
          "
        >
          <span>{{ 'registration.password_restriction' | translate }}</span>
        </div>
        <div
          class="err"
          *ngIf="!form.controls.confirmPassword.pristine && form.errors?.passwordMismatch && !form.get('confirmPassword').errors?.minlength"
        >
          <span>{{ 'registration.password_dont_match' | translate }}</span>
        </div>
      </div>
      <mat-checkbox formControlName="isAllowStatistics" class="sign-up-full-width" *ngIf="isDemoPageAvailable$ | async">
        <span class="white-space-fix"
          >{{ 'registration.statistics' | translate }}
          <a href="https://github.com/exadel-inc/CompreFace/blob/master/docs/Gathering-anonymous-statistics.md"
            >{{ 'registration.more_info' | translate }}
          </a>
        </span>
      </mat-checkbox>
    </form>
  </div>
  <div class="form-card--btn-wrapper">
    <button class="btn" mat-flat-button type="submit" form="signUpForm" [disabled]="form.invalid || (isLoading$ | async)">
      {{ 'registration.sign_up' | translate }}
    </button>
    <div class="link">
      {{ 'registration.have_account' | translate }}
      <a [routerLink]="[routes.Login]">{{ 'registration.login' | translate }}</a>
    </div>
    <div class="build-version">
      <span class="mat-caption">{{ 'applications.build' | translate }} {{ env.buildNumber }}</span>
    </div>
  </div>
</div>
